import { createStore } from 'redux'  // 引入createStore方法
import { persistStore, persistReducer } from "redux-persist";
import storage from 'redux-persist/lib/storage'

const persistConfig = {
    key: 'root',
    storage,
}

const defaultState = {
    userInfo: {},
    auth: [],
    staff:{}
};
const stateArr = ['userInfo', 'auth', 'staff'];

const persistedReducer = persistReducer(persistConfig, (state = defaultState, action) => {
    // 'pageInfo.house.pager'
    if(stateArr.includes(action.type)){
        let newState = JSON.parse(JSON.stringify(state))
        newState[action.type] = action.value
        state = newState
    } else {
        console.log(action.type+' 不支持修改')
    }
    return state
})

export const store = createStore(persistedReducer)
export const persistor = persistStore(store)